package net.cmkj.mine.core.admin.sys.dept;

import net.cmkj.mine.bean.SysDept;
import net.cmkj.mine.common.anno.RequiresPermissions;
import net.cmkj.mine.common.controller.BaseController;
import net.cmkj.mine.util.IWebUtils;

/**
 * 部门管理.
 */
public class DeptController extends BaseController {
	
	private DeptService service = DeptService.service;
	
	@RequiresPermissions(value={"/sys/dept"})
	public void index() throws Exception {
		render("dept.html");
	}
	
	@RequiresPermissions(value={"/sys/dept"})
	public void form() throws Exception {
		Integer id = this.getParaToInt("id");
		Boolean isadd = this.getParaToBoolean("isadd");
		if(isadd != null && isadd){
			if(id != null){
				SysDept sysDeptTmp = new SysDept();
				sysDeptTmp.setPid(service.findById(id).getId());
				setAttr("dept",sysDeptTmp);
			}
		}else{
			if(id != null){
				SysDept sysDept = service.findById(id);
				setAttr("dept",sysDept);
			}
		}
		render("deptForm.html");
	}
	
	@RequiresPermissions(value={"/sys/dept"})
	public void  getTreeGridView() throws Exception {
		this.renderJson(service.getTreeGridView());
	}
	
	@RequiresPermissions(value={"/sys/dept"})
	public void getZtreeViewList() throws Exception {
		this.renderJson(service.getZtreeViewList());
	}
	
	@RequiresPermissions(value={"/sys/dept"})
	public void save() throws Exception {
		Integer id=getParaToInt("id");
		String name=getPara("name");
		String seq=getPara("seq");
		String des=getPara("des");
		Integer pId=getParaToInt("pid");
		this.renderJson(service.save(id, name, seq, des, pId,IWebUtils.getCurrentSysUser(getRequest())));
	}

	@RequiresPermissions(value={"/sys/dept"})
	public void visible() throws Exception {
		Integer visible=this.getParaToInt("visible");
		Integer id=this.getParaToInt("id");
		this.renderJson(service.visible(id, visible));
	}

	@RequiresPermissions(value={"/sys/dept"})
	public void getDepts() throws Exception {
		renderJson(service.getDepts());
	}

}
